home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / doors / proc / proc.c
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.8 KB  |  127 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <libraries/dosextens.h>
  4.  
  5. extern void    *AllocMem(), *CreatePort(), *GetMsg(), *FindTask();
  6.  
  7. extern LONG    Open(), Output(), CreateProc();
  8.  
  9.  
  10. /*
  11.  * Cursor manipulation strings.
  12.  */
  13. char    fwdcursor[] = "\033[C";
  14. char    backcursor = '\b';
  15.  
  16. struct PhonySegList {
  17.     BPTR    psl_NextSeg;        /*  BPTR to next element in list  */
  18.     UWORD    psl_JMP;        /*  A 68000 JMP abs.l instruction  */
  19.     LONG    (*psl_EntryPoint)();    /*  The address of the function  */
  20. };
  21.  
  22. struct PhonySegList template = {
  23.     NULL,                /*  No next element.          */
  24.     0x4EF9,                /*  JMP abs.l              */
  25.     NULL                /*  Argument for JMP instruction  */
  26. };
  27.  
  28. LONG
  29. coprocess ()
  30. {
  31.     register int    i, n;
  32.     struct Process    *me;
  33.     struct Message    *startupmsg;
  34.     LONG        doswin;
  35.     char        buf[256];
  36.  
  37.     me = FindTask (NULL);
  38.     WaitPort (&me -> pr_MsgPort);
  39.     startupmsg = GetMsg (&me -> pr_MsgPort);
  40.  
  41.     if (!(doswin = Open ("CON:0/0/320/100/Sub-Process", MODE_NEWFILE)))
  42.         goto xit;
  43.  
  44.     Write (doswin, "This is the child speaking.\n", 28L);
  45.  
  46.     sprintf (buf, "I'm at 0x%lx\n", me);
  47.     Write (doswin, buf, (LONG) strlen (buf));
  48.  
  49.     sprintf (buf, "My stack size appears to be\n%ld bytes.\n",
  50.          me -> pr_StackSize);
  51.     Write (doswin, buf, (LONG) strlen (buf));
  52.  
  53.     sprintf (buf, "pr_StackBase is 0x%lx\n", me -> pr_StackBase);
  54.     Write (doswin, buf, (LONG) strlen (buf));
  55.  
  56.     for (n = 20;  n--; ) {
  57.         for (i = 35;  i--; )
  58.             Write (doswin, fwdcursor, sizeof (fwdcursor) - 1L);
  59.         for (i = 35;  i--; )
  60.             Write (doswin, &backcursor, 1L);
  61.     }
  62.  
  63.     Close (doswin);            /*  Get ridda da window.  */
  64. xit:
  65.     Forbid ();
  66.     ReplyMsg (startupmsg);
  67.     return (0);
  68. }
  69.  
  70.  
  71. main ()
  72. {
  73.     register int        i;
  74.     struct Process        *me;
  75.     struct MsgPort        *replyport = NULL;
  76.     struct Message        startupmsg;
  77.     struct PhonySegList    *fakelist = NULL;
  78.     LONG            child,
  79.                 priority,
  80.                 term;
  81.  
  82.     if (!(term = Output ()))
  83.         goto xit;
  84.  
  85.     if (!(replyport = CreatePort (NULL, NULL)))
  86.         goto xit;
  87.  
  88.     if (!(fakelist = AllocMem ((LONG) sizeof (*fakelist), NULL)))
  89.         goto xit;
  90.  
  91.     CopyMem (&template, fakelist, (LONG) sizeof (template));
  92.     fakelist -> psl_EntryPoint = coprocess;
  93.  
  94.     startupmsg.mn_Node.ln_Type    = NT_MESSAGE;
  95.     startupmsg.mn_Node.ln_Pri    = 0;
  96.     startupmsg.mn_ReplyPort        = replyport;
  97.  
  98.     me = FindTask (NULL);
  99.     priority = me -> pr_Task.tc_Node.ln_Pri;
  100.  
  101.     puts ("This is the parent speaking.");
  102.     printf ("I'm at 0x%lx\n", me);
  103.     printf ("My stack size appears to be\n%ld bytes.\n",
  104.          me -> pr_StackSize);
  105.     printf ("pr_StackBase is 0x%lx\n", me -> pr_StackBase);
  106.  
  107.     if (!(child = CreateProc ("Sub-Process",
  108.                   priority,
  109.                   (LONG) fakelist >> 2,
  110.                   2048L)))
  111.         goto xit;
  112.  
  113.     PutMsg (child, &startupmsg);
  114.  
  115.     while (!GetMsg (replyport)) {
  116.         for (i = 64;  i--; )
  117.             Write (term, fwdcursor, sizeof (fwdcursor) - 1L);
  118.         for (i = 64;  i--; )
  119.             Write (term, &backcursor, 1L);
  120.     }
  121.  
  122.     puts ("Child terminated.");
  123. xit:
  124.     if (fakelist)    FreeMem (fakelist, (LONG) sizeof (*fakelist));
  125.     if (replyport)    DeletePort (replyport);
  126. }
  127.